﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Star_Wars
{
    class RecordsManager
    {
        //public bool indicator = false;
        private string filename = "records.txt";
        private int[] records = new int[10];
        private FileInfo file;
        private bool needWriting = false;
        //private StreamReader sr;
        public RecordsManager()
        {
            //file = new FileInfo(filename);
            for (int i = 0; i < 10; i++)
            {
                records[i] = 0;
            }
            if (!File.Exists(filename))
            {
                WriteRecords();
            }
            else
            {
                ReadRecords();
            }
            //file.IsReadOnly = true;
        }
        
        public void AddRecord(int points)
        {
           // if (indicator)
            //{
                for (int i = 9; i >= 0; i--)
                {
                    if (points > records[i])
                    {
                        for (int j = 0; j <= i - 1; j++)
                        {
                            records[j] = records[j + 1];
                        }
                        records[i] = points;
                        break;
                    }
                }
                //indicator = false;
           // }
        }
        public int Record(int i)
        {
            return records[i];
        }
        public void WriteRecords()
        {
            StreamWriter sw = new StreamWriter(filename);
            for (int i = 0; i < 10; i++)
            {
                sw.WriteLine(records[i].ToString());
            }
            sw.Close();
        }
        public void ReadRecords()
        {
            StreamReader sr = new StreamReader(filename);
            for (int i = 0; i < 10; i++)
            {
                records[i] = Convert.ToInt32(sr.ReadLine());
            }
            sr.Close();
        }
    }
}
